﻿function isInElement(elem,x,y)
{
	off=elem.offset();
	if(x<off.left || x>off.left+elem.width())
		return false;
	if(y<off.top || y>off.top+elem.height())
		return false;
	return true;
}

function ctnKesu(){
	
}

function floatAbove(prntElem,subElem){
	prntElem.hover(function(e){
		this.subDisp=true;
		pp=$(this);
		subElem.css({'left':pp.offset().left,'top':pp.offset().top-subElem.height()-1}).show(0);
	},function(e){
		if(!isInElement(subElem,e.clientX,e.clientY))
		{
			this.subDisp=false;
			subElem.hide(0,ctnKesu);
		}
	});
	subElem.mouseleave(function(e){
		if(!this.subDisp)
			subElem.hide(0,ctnKesu);
	});
}

$(document).ready(function(){
	$('.mini-dormlink3>li').mouseover(function(e){
		if(!this.miniDisplayed)
		{
			this.miniDisplayed=true;
			pp=$(this);
			$(".mini-card-outline").css({'left':pp.offset().left+pp.width(),'top':pp.find('.mini-ucard-avatar').offset().top}).show();
		}
	});
	$('.mini-dormlink3>li').mouseleave(function(e){
		if(this.miniDisplayed)
		{
			this.miniDisplayed=false;
			outline=$(".mini-card-outline");
			if(!isInElement(outline,e.clientX,e.clientY))
				outline.hide();
		}
	});
	$(".mini-card-outline").mouseleave(function(e){
		$(this).hide();
	});
	/*
	$('#wodow1-1-1').hover(function(){
		if(!this.miniDisplayed)
		{
			this.miniDisplayed=true;
			pp=$(this);
			outline=$('.dorm-card-outline')
			outline.css({'left':pp.offset().left,'top':pp.offset().top-outline.height()}).show();
		}
	},function(e){
		if(this.miniDisplayed)
		{
			this.miniDisplayed=false;
			outline=$('.dorm-card-outline');
			if(!isInElement(outline,e.clientX,e.clientY))
				outline.hide();
		}
	});*/
	$('.dorm-card-outline').mouseleave(function(){
		$(this).hide();
	});
	floatAbove($('#wodow1-1-1'),$('.dorm-card-outline'));
	
	floatAbove($('.dorm-card-user1'),$('.mini-card-outline'));
});


/*back to top*/
XN.dom.ready(function(){
var bt = $('toolBackTo'),
hl = XN.browser.WebKit ? (Sizzle('body')[0]) : (Sizzle('html')[0]);
var winWidth =  window.innerWidth || document.body.clientWidth;
var nav = Sizzle('.navigation')[0];
if(winWidth >= 1120){
bt.style.left = XN.element.getPosition(nav).left + 990 +'px';
}else{
bt.style.right = '10px';
}
XN.event.addEvent(window, 'scroll', function(e){
var st = hl.scrollTop,
vh = hl.clientHeight,
show = (st>30);
if( show ){
bt.style.display = '';
}else{
bt.style.display = 'none';
}
});
XN.event.addEvent(window, 'resize', function(e){
winWidth =  window.innerWidth || document.body.clientWidth;
if(winWidth >= 1120){
bt.style.right = '';
bt.style.left = XN.element.getPosition(nav).left + 990 +'px';
}else{
bt.style.left = '';
bt.style.right = '10px';
}
});

});

